package servlet.admin.music;

import com.alibaba.fastjson.JSON;
import pojo.Result;
import pojo.Songs;
import service.MusicMngService;
import service.impl.MusicMngServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 作者：杨晋
 */
@WebServlet("/admin/searchMusicListServlet")
public class SearchSongsServlet extends HttpServlet {
    MusicMngService MusicMngService = new MusicMngServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取请求参数
        String nickName = req.getParameter("title");

        // 设置字符编码
        resp.setContentType("application/json;charset=UTF-8");
        List<Songs> users = MusicMngService.selectSongListByName(nickName);
        Result result = null;
        if (users != null) {
            result = Result.success(users);
        } else {
            result = Result.error("查询失败");
        }
        resp.getWriter().write(JSON.toJSONString(result));
    }
}